package com.yfht.framework.base.page.impl;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import com.yfht.framework.base.page.IQuery;


@SuppressWarnings("unchecked")
public class QueryBean implements IQuery {
	private int offset = 0;

	private int pageSize = 5;
	private int pageNum = 1;

	private Map queryParams = new HashMap<String, Object>();

	public void setOffset(int offset) {
		this.offset = offset;
	}

	/*
	 * (non-Javadoc)
	 * 
	 */
	public int getPageSize() {
		return pageSize;
	}

	private void reCalculateOffset() {
		this.offset = (pageNum - 1) * pageSize;
	}

	/*
	 * (non-Javadoc) calculate
	 * 
	 */
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
		this.reCalculateOffset();
	}

	/*
	 * (non-Javadoc)
	 * 
	 */

	public Map<String, Object> getQueryParams() {
		Map<String, Object> params = new HashMap<String, Object>();
		for (Iterator it = queryParams.entrySet().iterator(); it.hasNext();) {
			Map.Entry entry = (Map.Entry) it.next();
			params.put((String) entry.getKey(), entry.getValue()); // StringUtil.StrFilter((String))
		}
		return params;
	}

	/*
	 * (non-Javadoc)
	 * 
	 */
	public void setQueryParams(Map queryParams) {
		this.queryParams = queryParams;
	}

	public int getOffset() {
		return this.offset;
	}

	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
		this.reCalculateOffset();
	}

}
